package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.entity.bo.Doctorservice;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.service.DoctorserviceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 医事服务表(Doctorservice)表控制层
 *
 * @author makejava
 * @since 2022-03-21 17:19:03
 */
@RestController
@RequestMapping("doctorservice")
public class DoctorserviceController {
    /**
     * 服务对象
     */
    @Resource
    private DoctorserviceService doctorserviceService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Doctorservice selectOne(Integer id) {
        return this.doctorserviceService.queryById(id);
    }
    
    @RequestMapping("getDoctorserviceList")
    public ResultDTO getDoctorserviceList(@RequestBody Doctorservice doctorservice)
    {
        IPage<Doctorservice> ipage = doctorserviceService.queryDoctorserviceList(doctorservice);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertDoctorservice")
    public ResultDTO insertDoctorservice(@RequestBody Doctorservice doctorservice)
    {
        Doctorservice tmpDoctorservice = doctorserviceService.insert(doctorservice);
        if (tmpDoctorservice != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getDoctorserviceById")
    public ResultDTO getDoctorserviceById(@RequestBody Map<String, Integer> map)
    {
        int doctorserviceId = map.get("doctorserviceId");
        Doctorservice doctorservice = doctorserviceService.queryById(doctorserviceId);
        if (doctorservice==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(doctorservice);
    }

    @RequestMapping("updateDoctorservice")
    public ResultDTO updateDoctorservice(@RequestBody Doctorservice doctorservice)
    {
        if (doctorservice==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (doctorserviceService.update(doctorservice)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deleteDoctorservice")
    public ResultDTO deleteDoctorservice(@RequestBody Map<String,Integer> map)
    {
        int doctorserviceId = map.get("doctorserviceId");
        if (doctorserviceService.deleteById(doctorserviceId))
        {
            return ResultDTOBuilder.success("删除成功！");
        }
        return ResultDTOBuilder.failureMsg("删除失败！");
    }
}